import numpy as np
import soundfile as sf
import os

def create_test_audio():
    # Create a 5-second sine wave at 440 Hz (A4 note)
    duration = 5  # seconds
    sample_rate = 22050  # Hz
    frequency = 440  # Hz
    
    # Generate time array
    t = np.linspace(0, duration, int(sample_rate * duration), False)
    
    # Generate sine wave
    audio_data = np.sin(2 * np.pi * frequency * t)
    
    # Add some variation to make it more interesting for visualization
    # Add a second harmonic
    audio_data += 0.5 * np.sin(2 * np.pi * 2 * frequency * t)
    
    # Normalize to 16-bit range
    audio_data = audio_data / np.max(np.abs(audio_data))
    
    # Save as WAV first (easier to work with)
    wav_path = os.path.join("test_data", "test_audio.wav")
    sf.write(wav_path, audio_data, sample_rate)
    
    print(f"Test audio saved as {wav_path}")
    print("You can convert this to MP3 using your preferred audio tool")

if __name__ == "__main__":
    create_test_audio()